<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    function getValueByPath( obj, path ) {
      let paths = path.split( '.' ); // [ xxx, yyy, zzz ]
      // 先 取得 obj.xxx, 再取得 结果中的 yyy, 再取得 结果中的 zzz
      // let res = null;
      // res = obj[ paths[ 0 ] ];
      // res = res[ paths[ 1 ] ];
      // res = res[ paths[ 2 ] ];

      let res = obj;
      let prop;
      while( prop = paths.shift() ) {
        res = res[ prop ];
      }
      return res;
    }

    var o = {
      a: {
        b: {
          c: {
            d: {
              e: '正确了'
            }
          }
        }
      }
    };

    var res = getValueByPath( o, 'a.b.c.d.e' );
    var res = getValueByPath( o, 'a.b.c' );


    console.log( res );
    
  </script>
</body>
</html>